<template>
  <div>
    <!-- 车辆颜色维护 -->
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>

    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      columnsRef="zjvehicleColour"
      :onRowSelectChange="selectChangeHandle"
      :isSelectColumn="false"
      :onColumnsChange="columns => (this.columns = columns)"
    >
      <template slot="controls" slot-scope="props">
        <multiuse-button size="small" type="primary" @click="addHandle(1)">新增</multiuse-button>
        <multiuse-button size="small" type="primary" @click="addHandle(2)">导入</multiuse-button>
      </template>
    </FilterTable>
    <BaseDialog :visible.sync="visible" :title="'基本信息'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <childrenModel :rowData="formData" @close="emitcloseHandler" />
    </BaseDialog>
    <BaseDialog :visible.sync="addvisible" :title="'基本信息'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <addModel @close="addcloseHandler" />
    </BaseDialog>
    <BaseDialog :visible.sync="importVisible" :title="'导入'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <importFiles :rowData="formData" @close="importcloseHandler" />
    </BaseDialog>
  </div>
</template>
<script>
import { getList, importColor, getDealerUser } from '@/api/omSale/vehicleParameters/vehicleColour/index.js';
import { dictionary } from '@/utils/dictMixin';
import childrenModel from './childrenModel';
import importFiles from './importFiles';
import { exportExcelFile } from '@/utils';
import addModel from './addModel';
export default {
  name: 'businessParameters',
  data() {
    this.BaseTable = null;
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchApi: getList,
      fetchParams: {
        xhrAbort: true
      },
      formData: {},
      visible: false,
      addvisible: false,
      importVisible: false
    };
  },
  mixins: [dictionary],
  components: {
    childrenModel,
    addModel,
    importFiles
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  created() {
    this.getUser();
  },
  methods: {
    createdFrom() {
      return [
        {
          type: 'SELECT',
          label: '颜色类型',
          fieldName: 'colorType',
          placeholder: '请选择',
          itemList: this.createDictList('1608')
        },
        {
          type: 'INPUT',
          label: '颜色代码',
          fieldName: 'colorCode',
          placeholder: '请输入'
        },
        {
          type: 'INPUT',
          label: '颜色名称',
          fieldName: 'colorName',
          placeholder: '请输入'
        },
        {
          type: 'SELECT',
          label: '启用标记',
          fieldName: 'isValid',
          placeholder: '请选择',
          itemList: this.createDictList('1004')
        }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 50,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <multiuse-button size="mini" type="text" onClick={() => this.editHandle(props.row)}>
                  编辑
                </multiuse-button>
              </div>
            );
          }
        },
        {
          title: '颜色类型',
          dataIndex: 'colorType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1608'),
          dictItems: this.createDictList('1608'),
          render: props => {
            return <span>{this.createDictText(props.row.colorType, '1608')}</span>;
          }
        },
        {
          title: '颜色代码',
          dataIndex: 'colorCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '颜色名称',
          dataIndex: 'colorName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '创建人',
          dataIndex: 'createdBy',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [],
          editType: 'select',
          editItems: []
        },
        {
          title: '创建日期',
          dataIndex: 'createdAt',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '启用标记',
          dataIndex: 'isValid',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004'),
          render: props => {
            return <span>{this.createDictText(props.row.isValid, '1004')}</span>;
          }
        }
      ];
    },
    selectChangeHandle(row) {},
    addHandle(type) {
      if (type == 1) {
        this.addvisible = true;
      } else {
        this.importVisible = true;
      }
    },
    changeHandle(params) {
      this.fetchParams.xhrAbort = false;
      this.fetchParams = Object.assign({}, this.fetchParams, params);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    editHandle(data) {
      this.formData = data;
      this.visible = true;
    },
    addcloseHandler(val) {
      this.addvisible = false;
      if (val) {
        this.fetchParams = Object.assign({}, this.fetchParams);
      }
    },
    emitcloseHandler(val) {
      this.visible = false;
      if (val) {
        this.fetchParams = Object.assign({}, this.fetchParams);
      }
    },
    importcloseHandler() {
      this.importVisible = false;
      this.fetchParams = Object.assign({}, this.fetchParams);
    },
    async getUser() {
      let res = await getDealerUser();
      let empList = res.data.map(x => ({ text: x.employeeName, value: x.userId + '' }));
      this.columns.find(item => item.dataIndex === 'createdBy').editItems = empList; //操作姓名
      this.columns.find(item => item.dataIndex === 'createdBy').filterItems = empList;
    }
  }
};
</script>
